package collention;


import java.util.ArrayList;
import java.util.Collection;

/**
 * @Classname: CollectionDemo2
 * @Author: bromide
 * @CreateTime: 2022/4/2--17:01
 * @Version: V1.0
 * @Description: contains:包含
 * remove: 删除
 * 集合的某些操作会受元素equals方法影响，比如contains()和remove()
 */
public class CollectionDemo2 {
    public static void main(String[] args) {
        Collection c = new ArrayList();
        c.add(new Point(1, 2));
        c.add(new Point(3, 4));
        c.add(new Point(5, 6));
        c.add(new Point(7, 8));
        c.add(new Point(9, 0));
        c.add(new Point(1, 2));
        /*
            集合重写了toString方法。格式为:
            [元素1.toString(), 元素2.toString(), 元素3.toString(), ....]
         */
        System.out.println(c);

        Point p = new Point(1, 2);
        System.out.println("P:" + p);
        /*
            boolean contains(Object o)
            删除元素也是删除与给定元素equals对比为true的元素
            对于
         */
        boolean contains = c.contains(p);
        System.out.println("是否包含:" + contains);

        /*
            当删除时，只会删除集合中的一个元素
         */
        c.remove(p);
        System.out.println(c);
    }
}
